package com.kwedding.service.app;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.kwedding.bean.TB_Schedule;
import com.kwedding.dao.TB_ScheduleMapper;
import com.kwedding.dto.app.RequestScheduleListByMonth;
import com.kwedding.dto.app.ResponseScheduleList;
import com.kwedding.util.CheckedUtil;
import com.kwedding.util.Constants;
import com.kwedding.util.CopyerObject;
import com.kwedding.util.LoggerParent;
import com.kwedding.util.RequestErrorBackException;

@Service
public class SchduleService  extends  LoggerParent {

	@Autowired
	private TB_ScheduleMapper tb_ScheduleMapper;

	// 根据月份获取档期
	public List<ResponseScheduleList> getScheduleList(RequestScheduleListByMonth listByMonth) {
		CheckedUtil.isNull(listByMonth.getTime(), Constants.REQUEST_ERROR_1, "时间不能为空");
		List<TB_Schedule> schedules = tb_ScheduleMapper.getListByMonth(listByMonth.getTime(), listByMonth.getBrandId());
		List<ResponseScheduleList> responseScheduleLists = new ArrayList<>();
		if (schedules != null && schedules.size() > 0) {
			schedules.stream().forEach(r -> {
				ResponseScheduleList scheduleList = CopyerObject.copyerObject(r, ResponseScheduleList.class);
				scheduleList.setIdStr(r.getScheduleId().toString());
				responseScheduleLists.add(scheduleList);
			});
		} else {
			throw new RequestErrorBackException(Constants.REQUEST_ERROR_2, "该时间段档期暂未设置");
		}
		return responseScheduleLists;

	}
}
